__author__ = "ncll"
__data__ = "2020/11/27 16:02"

# 单例
'''class Person(object):
    __instance = None
    init_flg = True
    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            # 如果为空，证明是第一次创建实例，通过父类的__new__(cls)创建
            cls.__instance = object.__new__(cls)
            print("new")
        return cls.__instance

    def __init__(self, name):
        if self.init_flg == True:
            print("init")
            self.name = name
            self.init_flg = False

per = Person("a1")
print(id(per))
ppp = Person("a2")
print(id(ppp))'''

# 异常--
# 1、文件找不到  IOError,FileNotFoundError
'''try:
    open("1.txt")
except IOError:
    print("未找到文件")'''
# 2、变量未定义 NameError
'''try:
    print(a)
except NameError:
    print("变量没有定义")'''

# 3、捕获多个异常(IOError,NameError)
'''try:
    print(a)
    open("123.txt")

except (IOError,NameError):
    print("发现多个异常")'''

# 4、捕捉所有异常Exception
'''try:
    open("12.txt")
except Exception:
    print("捕获所有异常")'''

# 5、捕获异常并打印
try:
    open("1.txt")
except Exception as res:
    print("打印异常")
    print(res)

# list_stu = [{'序号': 1, '姓名': '陈小璐'}, {'序号': 2, '姓名': '陈中璐'}, {'序号': 3, '姓名': '陈大璐'}]
#
#
# # 删除学生信息
# try:
#
#     try:
#         open('test.txt')
#     except Exception as result:
#         print("捕捉异常")
#         print(result)
#     finally:
#         print("guanbi")
# except Exception as re:
#     print("没有捕捉到异常")



# def del_info():
#     try:
#
#         del_num = int(input("请输入要删除学生的序号"))
#         del_flag = input("确定删除，请输入 yes；取消删除，请输入 no ： ")
#         if del_flag == 'yes':
#             del list_stu[del_num-1]
#             print("已删除")
#         else:
#             print("取消删除")
#         print(list_stu)
#     except Exception as result:
#         print("没有该序号")
#         print(result)
#     else:
#         print("没有捕捉到异常")
#     finally:
#         print("close")
#
#
# # 修改学生信息
#
#
# def modify_info():
#     modify_num = int(input("请输入要修改学生的序号"))
#     print("你要修改的信息是：")
#     if 0 <= modify_num < len(list_stu):
#         list_stu[modify_num-1]['姓名'] = input("请输入新的姓名： ")
#         list_stu[modify_num-1]['手机号'] = input("请输入新的手机号： ")
#         list_stu[modify_num-1]['QQ'] = input("请输入新的QQ： ")
#     else:
#         print("输入错误")
#     print(list_stu)
#
# # 查询学生信息
#
#
# def search_info():
#     name = input("请输入要查询的学生姓名")
#     dic_stu = {}
#     for i in list_stu:
#         if name == i['姓名']:
#             print(i)
#         else:
#             print("查询不到该学生信息")
#     # for j in range(len(list_stu)):
#     #     if name == list_stu[j]['姓名']:
#     #         print(list_stu[j])
#     #         break
#     #     else:
#     #         print("查询不到该学生信息")
#
#
# # 打印学生信息
#
#
# def print_all_info():
#     print("所有学生的信息为：")
#     i = 1
#     for temp in list_stu:
#         print("%d 姓名:%s 手机号:%s QQ: %s" % (i, temp['姓名'], temp['手机号'], temp['QQ']))
#         i += 1
#
#
# def save_data():
#     print("保存信息")
#     file_stu = open("学生信息管理记事本", 'w', encoding='utf-8')
#     ii = 0
#     while ii < len(list_stu):
#         file_stu.write(str(list_stu[ii]))
#         ii += 1
#
# print(list_stu)
# del_info()


